{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def init(data):\n",
    "    data['first'] = {}\n",
    "    data['middle'] = {}\n",
    "    data['last'] = {}\n",
    "\n",
    "def lookup(data, label, name):\n",
    "    return data[label].get(name)\n",
    "\n",
    "\n",
    "def store(data, full_name):\n",
    "    names = full_name.split()\n",
    "    if len(names) == 2: names.insert(1, '')\n",
    "    labels = 'first', 'middle', 'last'\n",
    "    for label, name in zip(labels, names):\n",
    "        people = lookup(data, label, name)\n",
    "        if people:\n",
    "            people.append(full_name)\n",
    "        else:\n",
    "            data[label][name] = [full_name]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Cao Weidong']"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_name = {}\n",
    "init(my_name)\n",
    "store(my_name, 'Cao Weidong')\n",
    "lookup(my_name, 'middle', '')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('cao', 'wei', 'dong')"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = 'cao', 'wei', 'dong'\n",
    "a"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
